package com.kobe.game_60;

import java.util.Arrays;

/**
 * 
 * It can be seen that the number, 125874, and its double, 251748, contain
 * exactly the same digits, but in a different order. Find the smallest positive
 * integer, x, such that 2x, 3x, 4x, 5x, and 6x, contain the same digits.
 */
public class _52 {
    public static void main(String[] args) {
        for (int i = 1;; i++) {
            if (compareDitigal(i, i * 2) && compareDitigal(i, i * 3)
                    && compareDitigal(i, i * 4) && compareDitigal(i, i * 5)
                    && compareDitigal(i, i * 6)) {
                System.out.println(i);
                break;
            }
        }

    }

    /**
     * to judge whether the two numbers are combined by same digits
     */
    public static boolean compareDitigal(int a, int b) {
        char[] A = getOrderedArray(a);
        char[] B = getOrderedArray(b);
        if (A.length == B.length) {
            for (int i = 0; i < A.length; i++) {
                if (A[i] != B[i]) {
                    return false;
                }
            }
            return true;
        } else {
            return false;
        }
    }

    /**
     * 
     * sort array
     */
    public static char[] getOrderedArray(int in) {
        char[] array = String.valueOf(in).toCharArray();
        Arrays.sort(array);
        return array;

    }
}
